package com.yonyougov.devops.cruxcisupport.util;

public class CmdUtils {

    /**
     * 生成新增或者更新公钥的命令
     * @param publicKey
     * @return
     */
    public static String savePublicKey(String publicKey){
        String result = "sed -i '|" +  publicKey + "|d' /root/.ssh/authorized_keys ; [ `cat /root/.ssh/authorized_keys |wc -l` -eq 0 ] && echo '' > " +
                "/root/.ssh/authorized_keys && sed -i '1i\\" + publicKey + "' /root/.ssh/authorized_keys " +
                "|| sed -i '1i\\" + publicKey + "' /root/.ssh/authorized_keys";
        return result;
    }

    /**
     * 生成删除公钥的命令
     * @param publicKey
     * @return
     */
    public static String delPublic(String publicKey){
        String result = "sed -i '|" + publicKey + "|d' /root/.ssh/authorized_keys";
        return result;
    }
}
